#ifndef  __TIMER_IF_H__
#define  __TIMER_IF_H__

#include <stdint.h>

typedef enum
{
    TIMER_MODE_ONE_SHOT = 0,
    TIMER_MODE_CYCLIC,
    ///
    TIMER_MODE_MAX
}
TIMER_MODE;

typedef enum
{
    TIMER_STATE_INIT = 0,
    TIMER_STATE_IDLE,
    TIMER_STATE_ACTIVE,
    TIMER_STATE_TIMEOUT,
    ///
    TIMER_STATE_MAX,
}
TIMER_STATE;

typedef enum
{
    TIMER_EVENT_NONE = 0,
    TIMER_EVENT_TIMEOUT,
    ///
    TIMER_EVENT_MAX,
}
TIMER_EVENT;

typedef struct
{
    uint16_t period;
    uint16_t count;
    TIMER_STATE state;
    TIMER_EVENT event;
    TIMER_MODE mode;
    void * timeout_callback;
}
TIMER_DATA;

typedef void (TIMEOUT_CALLBACK)(TIMER_DATA * this);

extern int timer_init(TIMER_DATA * this, TIMEOUT_CALLBACK cb);
extern int timer_setPeriod(TIMER_DATA * this, uint16_t period);
extern int timer_start(TIMER_DATA * this, TIMER_MODE mode);
extern int timer_run(TIMER_DATA * this);
extern int timer_stop(TIMER_DATA * this);

extern TIMER_EVENT timer_getEvent(TIMER_DATA * this);
extern TIMER_STATE timer_getState(TIMER_DATA * this);

#endif // __TIMER_IF_H__
